<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : own_shoplink.php   FILE_PATH : D:\webroot\mulitishop\member\own_shoplink.php
 * ....店铺友情连接
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 网城创想多用户商城开发团队 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Tue Sep 11 16:40:39 CST 2007
 */

require_once("../global.inc.php");

class OwnShopLinkManage extends CommonFrameWork{
	/**
	 * 商铺连接对象
	 *
	 * @var obj
	 */
	var $obj_shoplink;
	/**
	 * 商铺对象
	 *
	 * @var obj
	 */
	var $obj_shop;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $objvalidate;

	function main(){

		/**
		 * 创建商铺连接对象
		 */
		if (!is_object($this->obj_shoplink)){
			require_once("shoplink.class.php");
			$this->obj_shoplink = new ShopLinkClass();
		}

		/**
		 * 创建商铺对象
		 */
		if (!is_object($this->obj_shop)){
			require_once("shop.class.php");
			$this->obj_shop = new ShopClass();
		}

		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}

		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("member");

		/**
		 * 语言包
		 */
		$this->getlang("shop");

		$this->_input['hideShopId'] = $_SESSION["s_shop"]['id'];

		/**
		 * 根据参数调用相应的方法
		 */
		switch ($this->_input['action']){
			case "del":
				$this->_delLink();
				break;
			case "save":
				$this->_saveLink();
				break;
			default:
				$this->shopMenuModule();
				$this->_showLink();
		}
	}

	/**
	 * 商铺友情连接查看
	 *
	 */
	function _showLink(){
		/**
		 * 得到商铺友情连接
		 */
		$link_array = $this->obj_shoplink->getLink($_SESSION['s_shop']['id'],$page);
		//print_r($link_array);
		$this->output("shop_link_array",   $link_array);    //输出店铺友情连接
		$this->showpage("own_shoplink.manage");   //显示页面
	}

	/**
	 * 保存商铺友情链接
	 *
	 */
	function _saveLink(){
		/**
		 * 根据会员名称得到店铺ID
		 */
		/**
		 * 创建会员对象
		 */

		require_once ("member.class.php");
		$objmember = new Member();
		/**
		 * 验证注册信息
		 */

		$this->objvalidate->setValidate(array("input"=>$this->_input['txtMemberName'],"require"=>"true","message"=>"请填写会员名称"));
		if ($error != "" ){
			$this->redirectPath("error","",$error);
		}else{
			$member_array = $objmember->getMemberList(array('member_name' => $this->_input['txtMemberName']),$page,"member_id");
			
			$this->_input['txtLinkShop'] = $member_array['0']['member_id'];
			if ($this->obj_shop->isHaveShop($this->_input['txtLinkShop']) == false){
				$this->redirectPath("error","","此会员并不拥有商铺");
			}else if ($this->_input['txtLinkShop'] == $_SESSION['s_login']['id']){
				$this->redirectPath("error","","您不能加自己为友情连接");
			}else if ($this->obj_shoplink->addLink($this->_input) == false){
				$this->redirectPath("error","","您已经加过此会员为友情连接了");
			}else{
				$this->redirectPath("succ","/member/own_shoplink.php","您已经成功加会员为友情连接！");
			}
		}
	}

	/**
	 * 删除一条或多条友情链接
	 *
	 */
	function _delLink(){
		$this->obj_shoplink->deleteOperateLink($this->_input["classid"],$_SESSION['s_shop']['id']);
		$this->redirectPath("succ","/member/own_shoplink.php","您已经成功删除了友情连接！");
	}

}
$link_manage = new OwnShopLinkManage();
$link_manage->main();
unset($link_manage);
?>